package com.ruoyi.supplier.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supplier.domain.TbRdc;
import com.ruoyi.supplier.service.ITbRdcService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配送中心Controller
 * 
 * @author ruoyi
 * @date 2021-02-16
 */
@RestController
@RequestMapping("/supplier/rdc")
public class TbRdcController extends BaseController
{
    @Autowired
    private ITbRdcService tbRdcService;

    /**
     * 查询配送中心列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:rdc:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbRdc tbRdc)
    {
        startPage();
        List<TbRdc> list = tbRdcService.selectTbRdcList(tbRdc);
        return getDataTable(list);
    }

    /**
     * 导出配送中心列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:rdc:export')")
    @Log(title = "配送中心", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbRdc tbRdc)
    {
        List<TbRdc> list = tbRdcService.selectTbRdcList(tbRdc);
        ExcelUtil<TbRdc> util = new ExcelUtil<TbRdc>(TbRdc.class);
        return util.exportExcel(list, "rdc");
    }

    /**
     * 获取配送中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('supplier:rdc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbRdcService.selectTbRdcById(id));
    }

    /**
     * 新增配送中心
     */
    @PreAuthorize("@ss.hasPermi('supplier:rdc:add')")
    @Log(title = "配送中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRdc tbRdc)
    {
        return toAjax(tbRdcService.insertTbRdc(tbRdc));
    }

    /**
     * 修改配送中心
     */
    @PreAuthorize("@ss.hasPermi('supplier:rdc:edit')")
    @Log(title = "配送中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRdc tbRdc)
    {
        return toAjax(tbRdcService.updateTbRdc(tbRdc));
    }

    /**
     * 删除配送中心
     */
    @PreAuthorize("@ss.hasPermi('supplier:rdc:remove')")
    @Log(title = "配送中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbRdcService.deleteTbRdcByIds(ids));
    }
}
